package com.example.administrator.u17.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.u17.R;
import com.example.administrator.u17.model.UpdateComics;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/11/15.
 */

public class UpdateAdapter extends BaseAdapter{
    private Context context;
    private List<UpdateComics> list;

    public UpdateAdapter(Context context, List<UpdateComics> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        UpdateViewHolder holder;
        if (convertView==null){
            convertView=View.inflate(context,R.layout.item_update,null);
            holder=new UpdateViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder=(UpdateViewHolder)convertView.getTag();
        }
        UpdateComics comics = list.get(position);
        holder.tvTitle.setText(comics.description);
        holder.tvGride.setText(comics.grade);
        Picasso.with(context).load(comics.cover).into(holder.iv);
        return convertView;
    }
    class UpdateViewHolder{
        TextView tvTitle,tvGride;
        ImageView iv;
        public UpdateViewHolder(View view){
            tvTitle=(TextView)view.findViewById(R.id.tv_item_update_title);
            tvGride=(TextView)view.findViewById(R.id.tv_item_update_gride);
            iv=(ImageView)view.findViewById(R.id.iv_item_update);
        }
    }
}
